package com.feicheng.controller.wx;

import com.alibaba.fastjson.JSONObject;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.common.util.StringGenerator;
import com.feicheng.persistence.entity.Astore;
import com.feicheng.service.a.FMdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("/wx/md")
@RequestMapping("/wx/md")
public class MdController {

    @Autowired
    FMdService fMdService;

    @PostMapping("/id/get")
    public ResultInfo getMdid(@RequestBody JSONObject param) {
        param.put("storeid", StringGenerator.getID("MD"));
        return ResultInfo.success(param);
    }

    @PostMapping("/page")
    public ResultInfo getMdByPage(@RequestBody JSONObject param) {
        param = fMdService.getMdByPage(param);
        return ResultInfo.success(param);
    }

    @PostMapping("/list")
    public ResultInfo getMdByList(@RequestBody JSONObject param) {
        param = fMdService.getMds(param);
        return ResultInfo.success(param);
    }

    @PostMapping("/info")
    public ResultInfo newMd(@RequestBody JSONObject param) {
        param = fMdService.newMd(param);
        return ResultInfo.success(param);
    }

    @PostMapping("/fjdd")
    public ResultInfo getFjdd(@RequestBody JSONObject param) {
        param = fMdService.getFjmd(param);
        return ResultInfo.success(param);
    }

    @PostMapping("/open")
    public ResultInfo open(@RequestBody JSONObject param) {
        fMdService.open(param);
        return ResultInfo.success();
    }

    @PostMapping("/close")
    public ResultInfo close(@RequestBody JSONObject param) {
        fMdService.close(param);
        return ResultInfo.success();
    }

    @PostMapping("/info/get")
    public ResultInfo getMd(@RequestBody JSONObject param) {
        param = fMdService.getMd(param);
        return ResultInfo.success(param);
    }

    @PostMapping("/info/put")
    public ResultInfo updateMd(@RequestBody Astore astore) {
        JSONObject param = new JSONObject();
        param.put("astore", astore);
        param = fMdService.updateMd(param);
        return ResultInfo.success(param);
    }

    @PostMapping("/info/remove")
    public ResultInfo removeMd(@RequestBody Astore astore) {
        JSONObject param = new JSONObject();
        param.put("astore", astore);
        param = fMdService.removeMd(param);
        return ResultInfo.success(param);
    }
}
